
/**
 * @Author: 陈瑞鹏
 * @Date:   2022-12-09 16:49:48
 * @Last Modified by:   陈瑞鹏
 * @Last Modified time: 2022-12-14 11:23:08
 */
import { Dictionary } from "../../utils/dictionary";
import barrackEntity from "./barrackEntity";

export default class barrackCtr {
  private static _ins: barrackCtr = null;

  public static get ins(): barrackCtr {
    if (this._ins == null) {
      this._ins = new barrackCtr();
    }
    return this._ins;
  }

  public barrackDic: Dictionary<any, barrackEntity>;

  public initTp(list) {
    this.barrackDic = new Dictionary();
    list.forEach(element => {
      if (element) {
        let barrackEny: barrackEntity = new barrackEntity();
        barrackEny.init(element);
        this.barrackDic.set(barrackEny.id, barrackEny);
      }
    });
  }

  public initData(arr) {

    arr.forEach(ele => {
      let barrackEny: barrackEntity = this.getBarrackById(Number(ele.id));
      barrackEny.isLock = ele.lock;
      barrackEny.level = ele.level;
      barrackEny.fragment = ele.fragment;
    })
  }

  public getBarrackById(id) {
    return this.barrackDic.get(id);
  }
}